<?php


class homeCtrl extends Ctrl{

    // 
    function _homeAct(){
        $tpl = DIR_THEME . '/root/home/_home.htm';
        if(file_exists($tpl)){ $tpl = '_home'; }
        else{ $tpl = 'yskit'; } //$tpl = '~home';
        $this->tpl([], $tpl);
    }

    function envTestAct(){ 
        $ua = Basic::envUA(); 
        $data['envs'] = [
            'UserOS' => extEnv::userOS(),
            'UserBrowser' => extEnv::userBrowser(),
            'UserIP' => Basic::envIP(),
            'HTTP_HOST' => $_SERVER['HTTP_HOST'],
            'REQUEST_URI' => $_SERVER['REQUEST_URI'],
            'PATH_INFO' => empty($_SERVER['PATH_INFO']) ? '' : $_SERVER['PATH_INFO'],
            'QUERY_STRING' => $_SERVER['QUERY_STRING'],
            'HTTP_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'],
            'route' => json_encode(App::route()),
            'argv' => empty($_SERVER['argv']) ? '' : json_encode($_SERVER['argv']),
        ];
        $data['lnk1'] = [
            'index_qstr' => '/index.php?r=home-envTest&k1=v1#' . path('r:home-envTest&k1=v1'),
            'php_path' => '/index.php/home-envTest?k1=v1&k2=v2#' . path('1:home-envTest?k1=v1'),
            'root_qstr' => '/?r=home-envTest&k1=v1#' . path('s:home-envTest&k1=v1'),
            'index_dir' => '/index/home-envTest?k1=v1&k2=v2#' . path('index:home-envTest?k1=v1'),
        ]; // r,1,2,index
        $data['lnk2'] = [
            'index_qstr' => '/index.php?r=home-vcode&k1=v1',
            'php_path' => '/index.php/home-vcode?k1=v1&k2=v2',
            'root_qstr' => '/?r=home-vcode&k1=v1',
            'index_dir' => '/index/home-vcode?k1=v1&k2=v2',
        ];
        $this->tpl($data);
    }

    // --key:{value}; -=> var(--key);  ie11-不支持:css-var()
    function weysVarAct(){
        $dfp = DIR_STATIC."/weys/weys.css"; 
        $data = file_get_contents($dfp);
        $data = extEnv::cssVar($data);
        header('Content-type:text/css;charset=utf-8');
        echo $data;
    }

    function vcodeDemoAct(){
        $data = [];
        for($i=0;$i<3;$i++){
            $data[$i] = Vcode::tabrc(6, 1);
        } 
        $this->tpl(['data'=>$data], 'vcode');
    }

    function vcodeAct(){
        sess_on();
        $type = uval('type'); // emtel, vsms4, xxx
        $mod = uval('mod'); // login, reg
        $code = $type=='emtel' ? uval('code') : ''; 
        $code = Encode::sysRevert($code, 1);
        new Vcode($type, $mod, $code);
    }

    function qrAct(){
        $text = uval('text'); $host = uval('host');
        $margin = uval('margin',4);
        if($host=="1"){
            $text = (Basic::isHttps() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $text;
        }
        include_once DIR_VENDOR."/sinclass/QRcode.php";
        \QRcode::png($text, false, 2, 3, $margin); // ($text, $outfile, $level, $size, $margin);
    }

    function scanAct(){
        $data['view'] = $this->mkvs['view']; // <def>, dir, view
        $data['redir'] = uval('redir');
        $data['debug'] = uval('debug', '0'); //dump($data);
        $data['isWxmob'] = Basic::isMobile() && Basic::isWeixin();
        // 在服务端生成签名
        include_once DIR_VENDOR . "/wwjsdk/lib/WwJssdk.php";
        $jssdk = new \WwJssdk('AppAB'); 
        $data['signPackage'] = $jssdk->getSignPackage();
        $data['signAgent'] = $jssdk->getSignPackage(1);
        $this->tpl($data);
    }

}
